/**
 * 给定数组A和B，有一个矩阵，Cij=Ai*Bj
 * 在C中求一个子矩形，使得和最大。
 * DP，忘了怎么实现的
 */
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;

template<typename T>
void input(vector<T> & v, int n){
	v.assign(n + 1, {});
	for(int i=1;i<=n;++i) cin >> v[i];
	return;
}

using Real = long double;
using llt = long long;
using vi = vector<int>;
using pii = pair<int, int>;

llt const INF = 0x3F4F5F6F7F8F9FAF;

int N, M;
vector<llt> A, B;

llt proc(const vector<llt> & v, int n){
	vector<llt> d(n + 1, -INF), z(n + 1, -INF);
    for(int i=1;i<=n;++i){
		z[i] = max(v[i], v[i] + z[i - 1]);
		d[i] = max(d[i - 1], z[i]);
	}
	return d[n];
}

llt proc2(const vector<llt> & v, int n){
	vector<llt> d(n + 1, INF), z(n + 1, INF);
	for(int i=1;i<=n;++i){
		if(abs(v[i]) <= abs(v[i] + z[i - 1])){
			z[i] = v[i];
		}else{
			z[i] = v[i] + z[i - 1];
		}
		d[i] = min(abs(z[i]), d[i - 1]);
	}
	return d[n];
}

llt proc3(const vector<llt> & v, int n){
	vector<llt> d(n + 1, INF), z(n + 1, INF);
	for(int i=1;i<=n;++i){
		z[i] = min(v[i], v[i] + z[i - 1]);
		d[i] = min(z[i], d[i - 1]);
	}
	return d[n];
}

llt proc(){
	auto ta = proc(A, N);
	auto tb = proc(B, M);

	// auto a2 = proc2(A, N);
	// auto b2 = proc2(B, M);

	auto a3 = proc3(A, N);
	auto b3 = proc3(B, M);

	auto ans = ta * tb;
    ans = max(ans, ta * b3);
	ans = max(ans, a3 * tb);
	ans = max(ans, a3 * b3);
    return ans;

}

void work(){
    cin >> N >> M;
	input(A, N);
	input(B, M);
	cout << proc() << endl;
	return;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int nofkase = 1;
    // cin >> nofkase;
    while(nofkase--) work();
    return 0;
}